package me.xinping.libs.views.extensions

import android.app.Activity
import android.app.ActivityOptions
import android.content.Intent
import android.os.Build
import me.xinping.libs.views.R

/**
 *Activity跳转切换
 */
fun Activity.skip2Act(intent: Intent, requestCode: Int = -1, isFinish: Boolean = false) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        when (requestCode) {
            -1 -> this.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle())
            else -> this.startActivityForResult(
                intent,
                requestCode,
                ActivityOptions.makeSceneTransitionAnimation(this).toBundle()
            )
        }

    } else {
        this.overridePendingTransition(R.anim.alpha_enter, R.anim.alpha_exit)
    }
    when (requestCode) {
        -1 -> this.startActivity(intent)
        else -> this.startActivityForResult(intent, requestCode)
    }
    if (isFinish) {
        this.finish()
    }
}